
using System;
using System.Net;
using System.IO;

namespace CouchFS
{


	public class RESTHelper
	{
		public static bool RequestGet(String host, String uri, out String content)
		{
			
			int port = 5984;
			content = String.Empty;
			String url = String.Format("http://{0}:{1}/couchfs/_view/tree/getdirectory?key=\"/root{2}\"", host, port.ToString(), uri);
			try
			{
				WebRequest request = WebRequest.Create (url);
				WebResponse response = request.GetResponse(); 
				StreamReader reader = new StreamReader(response.GetResponseStream()); 
				
				while (reader.Peek() >= 0)
				{
		        	string line = reader.ReadLine();
					content += line;
				}
				return true;
			}
			catch (Exception e)
			{
				content = e.Message;
			}

			return false;
		}
	}
}
